package com.Sdebruijn.curriculumvitae;

import org.jivesoftware.smack.packet.Message;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.Sdebruijn.curriculumvitae.xmpp.OnNewMessageListener;
import com.Sdebruijn.curriculumvitae.xmpp.XmppManager;
import com.Sdebruijn.secrets.chat.Secret;

public class ChatActivity extends BaseActivity implements OnNewMessageListener, Secret {
	XmppManager xmpp;
	private ListView mList;
	ArrayAdapter<String> adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chat);
		xmpp = new XmppManager(this);
		mList = (ListView) this.findViewById(R.id.listMessages);
		setListAdapter();
		
		Message msg = xmpp.buildMessage(CHAT_BUDDY, "testmessage");
		xmpp.sendMessage(msg);


	}

	@Override
	public void OnNewMessageSend(Message message) {
		adapter.notifyDataSetChanged();
	}

	@Override
	public void OnNewMessageReceived(Message message) {
		adapter.notifyDataSetChanged();
	}

	private void setListAdapter() {
		adapter = new ArrayAdapter<String>(this, R.layout.list_item_chat,
				xmpp.messages);

		mList.setAdapter(adapter);
	}

}
